package com.woniu.zhoukao.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Component
public class SendEmailConsumer {

    @RabbitListener(queues = "sendEmailQueue")
    public void onMsg(String msg, Channel channel, Message message) throws IOException {

        System.out.println("-----------------SendEmailConsumer 收到消息 "+msg);


        System.out.println("准备发送邮件");

        System.out.println("执行邮件的发送");
        try {
            //模拟邮件发送过程出现网络阻塞
            TimeUnit.SECONDS.sleep(30);  //当前线程暂停30s
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }


        System.out.println("邮件发送成功");

        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }



}
